#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>

int print_test() {
  printf("%d\n", 10);
  //  usleep(2000000);
}
int main(void)
{
  while(true) {
    pid_t pid;
    pid = fork();
    if(pid < 0){
      perror("fork error");
      exit(EXIT_FAILURE);
    }
    if(pid == 0){
      printf("this is child process\n");
      print_test();
      sleep(5);
      exit(0);

    } else {
      int status;
      pid_t ret;
      ret = waitpid(pid,&status,/*WNOHANG*/0);
      if(ret <0){
        perror("wait error");
        exit(EXIT_FAILURE);
      }
      printf("ret = %d pid = %d\n", ret, pid);
      if (WIFEXITED(status))
        printf("child exited normal exit status=%d\n", WEXITSTATUS(status));

      else if (WIFSIGNALED(status))
        printf("child exited abnormal signal number=%d\n", WTERMSIG(status));
      else if (WIFSTOPPED(status))
        printf("child stoped signal number=%d\n", WSTOPSIG(status));
    }
  }
  return 0;
}
